﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using VehicleRecordSystem.util;

namespace VehicleRecordSystem.view
{
    /// <summary>
    /// Interaction logic for DrivePage.xaml
    /// </summary>
    public partial class DrivePage : Page
    {
        private static DrivePage instanse;
        private string errorBackgroundColor = "#EBA4B0";

        public static DrivePage Instanse
        {
            get
            {
                if (instanse == null)
                {
                    instanse = new DrivePage();
                }

                return instanse;
            }
        }

        public DrivePage()
        {
            InitializeComponent();
        }

        private void btnDrivePageSave_Click(object sender, RoutedEventArgs e)
        {
            if (validate())
            {
                DateTime? start_date = datePickerStartDate.SelectedDate;
                Single start_odometer = Convert.ToSingle(txtStartOdometer.Text);
                DateTime? end_date = datePickerEndDate.SelectedDate;
                Single end_odometer = Convert.ToSingle(txtEndOdometer.Text);
                String from = txtFrom.Text;
                String to = txtTo.Text;
                String is_shedule;
                if((Boolean)rbYes.IsChecked)
                {
                    is_shedule = rbYes.Content.ToString();
                }
                else
                {
                    is_shedule = rbNo.Content.ToString();
                }
                
            }

        }

        private Boolean validate()
        {
            Boolean ok = true;
            var bc = new BrushConverter();

            if (string.IsNullOrEmpty(datePickerStartDate.SelectedDate.ToString()))
            {
                ok = false;
                datePickerStartDate.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (string.IsNullOrEmpty(txtStartOdometer.Text))
            {
                ok = false;
                txtStartOdometer.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (!VRSValidate.isNumberic(txtStartOdometer.Text))
            {
                ok = false;
                txtStartOdometer.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (string.IsNullOrEmpty(datePickerEndDate.SelectedDate.ToString()))
            {
                ok = false;
                datePickerEndDate.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (string.IsNullOrEmpty(txtEndOdometer.Text))
            {
                ok = false;
                txtEndOdometer.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (!VRSValidate.isNumberic(txtEndOdometer.Text))
            {
                ok = false;
                txtEndOdometer.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (string.IsNullOrEmpty(txtFrom.Text))
            {
                ok = false;
                txtFrom.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            if (string.IsNullOrEmpty(txtTo.Text))
            {
                ok = false;
                txtTo.Background = (System.Windows.Media.Brush)bc.ConvertFrom(errorBackgroundColor);
            }
            return ok;
        }

        private void changeBackgroundColorToNormal(object sender, RoutedEventArgs e)
        {
            var bc = new BrushConverter();

            if (sender is TextBox)
            {
                TextBox txt = (TextBox)sender;
                txt.Background = (System.Windows.Media.Brush)bc.ConvertFrom("#FFFFFFFF");
            }
            if (sender is DatePicker)
            {
                DatePicker dp = (DatePicker)sender;
                dp.Background = (System.Windows.Media.Brush)bc.ConvertFrom("#FFFFFFFF");
            }
            if (sender is ComboBox)
            {
                ComboBox dp = (ComboBox)sender;
                dp.Background = (System.Windows.Media.Brush)bc.ConvertFrom("#FFFFFFFF");
            }
        }
   }

}
